package msigraphx.gibbsSampler;

import java.util.List;
import java.util.Vector;

public abstract class RandomVariable<Type> {
	protected String name;
	protected RandomVariableValue<Type> value;
	protected List<RandomVariableValue<Type>> allowedValues;

	public RandomVariable(String name) {
		super();
		this.name = name;
		this.value = new RandomVariableValue<Type>(this);
		this.allowedValues = new Vector<RandomVariableValue<Type>>();
	}
	
	public RandomVariable(String name, RandomVariableValue<Type> value,
			List<RandomVariableValue<Type>> allowedValues) {
		super();
		this.name = name;
		this.value = value;
		this.allowedValues = allowedValues;
	}
	
	public boolean equals(Object other) {
		if(!(other instanceof RandomVariable<?>)) {
			return false;
		}
		RandomVariable<?> otherRandVar = (RandomVariable<?>)other;
		if(!otherRandVar.getClass().equals(this.getClass())) {
			return false;
		}
		if(!otherRandVar.name.equals(this.name)) {
			return false;
		}
		
		return true;
	}
	
	public int hashCode() {
		return name.hashCode();
	}

	public RandomVariableValue<Type> getValue() {
		return value;
	}

	public void setValue(RandomVariableValue<Type> value) {
		this.value = value;
	}

	public List<RandomVariableValue<Type>> getAllowedValues() {
		return allowedValues;
	}

	public void setAllowedValues(List<RandomVariableValue<Type>> allowedValues) {
		this.allowedValues = allowedValues;
	}
	
	public void addAllowedValue(RandomVariableValue<Type> val) {
		allowedValues.add(val);
	}
	
	public RandomVariableValue<Type> getAllowedValue(int allowedValueIndex) {
		return allowedValues.get(allowedValueIndex);
	}
	
	public String getName() {
		return name;
	}
}
